﻿using System;
using System.Collections.Generic;
using KlavoNotifications.Fetch;
using KlavoNotifications.Utils;
using KlavoNotifications.ViewModels.Tray;
using Microsoft.Practices.Prism.Commands;

namespace KlavoNotifications.ViewModels.Notification
{
    public class BalloonViewModel : GamesListViewModel
    {
        private readonly DelegateCommand _closeCommand;

        public BalloonViewModel(List<Game> games, int timestamp)
            : base()
        {
            _closeCommand = new DelegateCommand(CloseCommandExecuted);

            foreach (Game xGame in games)
            {
                TrayItemViewModel item = ItemFromData(xGame, timestamp);
                if (item != null)
                    _items.Add(item);
            }

            _timer.Start();
        }        

        public DelegateCommand CloseCommand
        {
            get { return _closeCommand; }
        }

        private void CloseCommandExecuted()
        {
            TaskBar tb = App.Get<TaskBar>();
            tb.CloseBalloon();
        }

        protected override void NavigateCommandExecuted(TrayItemViewModel item)
        {
            base.NavigateCommandExecuted(item);

            TaskBar tb = App.Get<TaskBar>();
            tb.CloseBalloon();
        }
    }
}